﻿#include "stdafx.h"
#include "litelog.h"
#include <sstream>
#include <future>



int main()
{
	std::cout << "Hello CMake." << std::endl;
	std::cout << LiteUtils::getCurrentTime(LiteUtils::MILLISECOND_LEVEL) << std::endl;
	LiteLog::instance()->init("log.txt");
	//LiteLog::instance()->setDebugPrint(false);
	//LiteLog::instance()->writeInfo("111", std::string("0000"), std::string("ppp"));
	int count = 100;
	std::promise<void> promise;
	auto shareF = promise.get_future().share();
	while (count--)
	{
		std::thread thr([count, &shareF]()
			{
				std::cout << "thread create:" << std::this_thread::get_id() << std::endl;
				shareF.wait();
				std::cout << "thread run:" << std::this_thread::get_id() << std::endl;
				int a = 1000;
				while (a--)
				{
					std::ostringstream oss;
					oss << std::this_thread::get_id() << ":" << count << "===" <<a;

					srand(count * 3456 * a);
					int a = rand();
					std::this_thread::sleep_for(std::chrono::milliseconds(a % 1000));
					LITE_LOG(Info, oss.str());


					srand(count * 123 *a);
					int b = rand();
					std::this_thread::sleep_for(std::chrono::milliseconds(100));
					LITE_LOG(Warning, oss.str());

					srand(count * 123789 *a);
					int c = rand();
					std::this_thread::sleep_for(std::chrono::milliseconds(c % 1000));
					LITE_LOG(Error, oss.str());
				}
			});
		thr.detach();
	}
	std::this_thread::sleep_for(std::chrono::milliseconds(5000));
	std::cout << "================================================================" << std::endl;
	promise.set_value();
	std::this_thread::sleep_for(std::chrono::milliseconds(5000));
	return 0;
}
